package com.hig.ledger.controller;

import java.util.List;

import com.hig.ledger.domain.LedgerConfinedSpace;
import com.hig.ledger.service.ILedgerConfinedSpaceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 受限空间台账Controller
 * 
 * @author scp
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/ledger/space")
public class LedgerConfinedSpaceController extends BaseController
{
    @Autowired
    private ILedgerConfinedSpaceService ledgerConfinedSpaceService;

    /**
     * 查询受限空间台账列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:list')")
    @GetMapping("/list")
    public TableDataInfo list(LedgerConfinedSpace ledgerConfinedSpace)
    {
        startPage();
        List<LedgerConfinedSpace> list = ledgerConfinedSpaceService.selectLedgerConfinedSpaceList(ledgerConfinedSpace);
        return getDataTable(list);
    }

    /**
     * 导出受限空间台账列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:export')")
    @Log(title = "受限空间台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LedgerConfinedSpace ledgerConfinedSpace, HttpServletResponse response)
    {
        List<LedgerConfinedSpace> list = ledgerConfinedSpaceService.selectLedgerConfinedSpaceList(ledgerConfinedSpace);
        ExcelUtil<LedgerConfinedSpace> util = new ExcelUtil<LedgerConfinedSpace>(LedgerConfinedSpace.class);
        util.exportExcel(response,list, "受限空间台账");
    }

    /**
     * 获取受限空间台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ledgerConfinedSpaceService.selectLedgerConfinedSpaceById(id));
    }

    /**
     * 新增受限空间台账
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:add')")
    @Log(title = "受限空间台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LedgerConfinedSpace ledgerConfinedSpace)
    {
        return toAjax(ledgerConfinedSpaceService.insertLedgerConfinedSpace(ledgerConfinedSpace));
    }

    /**
     * 修改受限空间台账
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:edit')")
    @Log(title = "受限空间台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LedgerConfinedSpace ledgerConfinedSpace)
    {
        return toAjax(ledgerConfinedSpaceService.updateLedgerConfinedSpace(ledgerConfinedSpace));
    }

    /**
     * 删除受限空间台账
     */
    @PreAuthorize("@ss.hasPermi('ledger:space:remove')")
    @Log(title = "受限空间台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ledgerConfinedSpaceService.deleteLedgerConfinedSpaceByIds(ids));
    }
}
